package {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.events.MouseEvent;
	import flash.display.MovieClip;
	import flash.geom.Point;
 
	public class m1 extends MovieClip {
		var paintStage:BitmapData=new BitmapData(550,400,false,0xFFFFFF);
		var paintDisplay:Bitmap=new Bitmap(paintStage);
		var drawing:Boolean=new Boolean(false);
 
		var vx:Number=new Number(0);
		var vy:Number=new Number(0);
		var len:uint=new uint;
		var i:uint=new uint();
 
		var p0:Point=new Point();
		var p1:Point=new Point();
 
		public function m1() {
			addChild(paintDisplay);
			stage.addEventListener(MouseEvent.MOUSE_DOWN,md);
			stage.addEventListener(MouseEvent.MOUSE_UP,mu);
			stage.addEventListener(MouseEvent.MOUSE_MOVE,mm);
		}
		
		function md(event:MouseEvent) {
			drawing=true;
			p0.x=event.stageX;
			p0.y=event.stageY;
			p1.x=p0.x;
			p1.y=p0.y;
		}
		
		function mu(event:MouseEvent) {
			drawing=false;
		}
		
		function mm(event:MouseEvent) {
			if (drawing) {
				p1.x=event.stageX;
				p1.y=event.stageY;
				paintStage.setPixel(event.stageX,event.stageY,0x000000);
				vx=p1.x-p0.x;
				vy=p1.y-p0.y;
				len=Math.sqrt(vx*vx+vy*vy);
				vx/=len;
				vy/=len;
				for (i=0; i<len; i++) {
					paintStage.setPixel(p0.x+(vx*i),p0.y+(vy*i),0x000000);
				}
				p0.x=p1.x;
				p0.y=p1.y;
			}
		}
	}
}